# -*- coding: utf-8 -*-
"""
Created on Thu Oct 22 18:05:11 2020

@author: Administrator
"""
#栈
class Stack(object):
    
    #初始化
    def __init__(self):
        self.__items=[]      
      
     #压栈   
    def push(self,v):
        self.__items.append(v)
     #出栈  
    def pop(self):
        return self.__items.pop()
    
    #栈是否为空
    def isEmpty(self):
        return self.__items==[]
    
    #转字符
    def __str__(self):
        return str(self.__items)
    
    #求长度
    def __len__(self):
        return len(self.__items)
    
    def size(self):
        return len(self.__items)
    
    #返回栈顶元素
    def peek(self):
        return self.__items[self.size()-1]
    
###################################################################################
class Queue(object):
     
    def __init__(self,items=[]):
         self.__items=items
         
    def __str__(self):
        return str(self.__items)
         
    
    def size(self):
        return len(self.__items)
    
    def isEmpty(self):
        return self.__items==[]
    
    #入队
    def enqueue(self,v):
        self.__items.insert(0,v)
    
        
    #出队
    def dequeue(self):
     
        return self.__items.pop()
       
###################################################################################
#单链
class SingleLinkNode(object):
    
    def __init__(self,item=None,nextp=None):
        self.item=item
        self.nextp=nextp
        
    def __str__(self):
        return str(self.item)
    
    
class SingleLink(object):
    
    #初始化
    def __init__(self):
        self.head=None
        self.tail=None
        self.length=0
        
    def __len__(self):
        return self.length
      
    #末尾添加节点
    def append(self,v:SingleLinkNode):
        if(self.length==0):
            self.head=v
            self.tail=v
            self.length=1
        else:
            self.tail.nextp=v
            self.tail=v
            self.length=self.length+1
            
    def __iter__(self):
        pointer=self.head
        while(pointer!=None):
            yield pointer
            pointer=pointer.nextp       
